 <?php
 
 Kurogo::includePackage('db');

 class FormWebModule extends WebModule
 {
   protected $id='form';
   protected function initializeForPage() {

     switch ($this->page)
     {
         case 'index':
             $this->assign('message', 'Post');
             $db = new db();
             $sql = "SELECT acronym FROM location ORDER BY acronym";
             $result = $db->query($sql, array('acronym'));
             $acronymlist = array();
             while ($row = $result->fetch()) {
                 $acronym = $row['acronym'];
                 $acronymlist[] = $acronym;
             }
             $this->assign('acronyms',$acronymlist);
             break;
             
         case 'form-submit':
             $db = new db();
             $session = $this->getSession();
             if($this->isLoggedIn()) {
                $user = $session->getUser();
                $userID = $user->getUserID();
                $sql = "SELECT locationID FROM location WHERE acronym='$_POST[acronym]'";
                $result = $db->query($sql,array('locationID'));
                $row = $result->fetch();
                $locationID = $row['locationID'];
                $sql = "INSERT INTO post (fbID, message, locationID) VALUES ('$userID','$_POST[message]','$locationID')";
                $db->query($sql);

                $this->assign('message', 'Success!');
             }
             else {
                $this->assign('message', 'Login');
             }
        
             break;
      }
   }
 }